package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.JinRiDingDanHomeBean;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.DingDanXiangQingHomeActivity;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.tui_huo_tui_kuan.THXQActivity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by 001 on 2017/9/21.
 */

public class JinRiDingDanHomeAdapter extends RecyclerView.Adapter<JinRiDingDanHomeAdapter.ViewHolder> {

    private Context mContext;
    private List<JinRiDingDanHomeBean> mList;

    public JinRiDingDanHomeAdapter(Context mContext, List<JinRiDingDanHomeBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public JinRiDingDanHomeAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_jin_ri_ding_dan_home, parent, false);

        final ViewHolder holder = new ViewHolder(view);

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //根据订单状态跳转到相应界面
                String state = holder.tv_zhuangTai.getText().toString().trim();
                switch (state) {
                    case "待发货":
                        Intent daiFaHuoIntent = new Intent(mContext, DingDanXiangQingHomeActivity.class);
                        daiFaHuoIntent.putExtra("dingDanState", state);
                        daiFaHuoIntent.putExtra("dingDanHao","1");
                        mContext.startActivity(daiFaHuoIntent);
                        break;
                    case "已发货":
                        Intent yiFaHuoIntent = new Intent(mContext, DingDanXiangQingHomeActivity.class);
                        yiFaHuoIntent.putExtra("dingDanState", state);
                        yiFaHuoIntent.putExtra("dingDanHao","1");
                        mContext.startActivity(yiFaHuoIntent);
                        break;
                    case "已完成":
                        Intent yiWanChengIntent = new Intent(mContext, DingDanXiangQingHomeActivity.class);
                        yiWanChengIntent.putExtra("dingDanState", state);
                        yiWanChengIntent.putExtra("dingDanHao","1");
                        mContext.startActivity(yiWanChengIntent);
                        break;
                    case "待付款":
                        Intent daiFuKuanIntent = new Intent(mContext, DingDanXiangQingHomeActivity.class);
                        daiFuKuanIntent.putExtra("dingDanState", state);
                        daiFuKuanIntent.putExtra("dingDanHao","1");
                        mContext.startActivity(daiFuKuanIntent);
                        break;
                    //退货退款
                    case "退款退货":
                    case "已换货":
                    case "已退款":
                        Intent tuiKuanIntent = new Intent(mContext, THXQActivity.class);
                        tuiKuanIntent.putExtra("dingDanState", state);
                        mContext.startActivity(tuiKuanIntent);
                        break;
                }
            }
        });

        return holder;
    }

    @Override
    public void onBindViewHolder(JinRiDingDanHomeAdapter.ViewHolder holder, int position) {

        JinRiDingDanHomeBean bean = mList.get(position);

        Glide.with(mContext).load(bean.logoUrl).into(holder.circle_photo);
        holder.tv_zhuangTai.setText(bean.zhuangTai);

        //根据订单状态 显示UI
        switch (bean.zhuangTai) {
            case "待发货":
                holder.rl_bottom.setVisibility(View.VISIBLE);
                holder.tv_left.setText("联系买家");
                holder.tv_right.setText("发货");
                break;
            case "已发货":
                holder.rl_bottom.setVisibility(View.VISIBLE);
                holder.tv_left.setText("联系买家");
                holder.tv_right.setText("等待接收");
                break;
            case "已完成":
                holder.rl_bottom.setVisibility(View.GONE);
                break;
            case "待付款":
                holder.rl_bottom.setVisibility(View.GONE);
                break;
            case "退款退货":
            case "已换货":
            case "已退款":
                holder.tv_heJi.setVisibility(View.VISIBLE);
                holder.rl_bottom.setVisibility(View.VISIBLE);
                holder.tv_right.setText("详情");
                holder.tv_left.setText("确认");
                break;
        }


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        View view;
        CircleImageView circle_photo;//头像
        TextView tv_zhuangTai;//状态
        RelativeLayout rl_bottom;//底部按钮
        TextView tv_left;//底部 左边 按钮
        TextView tv_right;//底部 右边 按钮
        TextView tv_heJi;

        public ViewHolder(View itemView) {
            super(itemView);

            view = itemView;
            circle_photo = (CircleImageView) itemView.findViewById(R.id.circle_photo);
            tv_zhuangTai = (TextView) itemView.findViewById(R.id.tv_zhuangTai);
            rl_bottom = (RelativeLayout) itemView.findViewById(R.id.rl_bottom);
            tv_left = (TextView) itemView.findViewById(R.id.tv_left_bottom);
            tv_right = (TextView) itemView.findViewById(R.id.tv_right_bottom);
            tv_heJi = (TextView) itemView.findViewById(R.id.tv_heJi);
        }
    }
}
